package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.AlertData;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.DeviceDataQueryDTO;
import com.zzyl.nursing.dto.ElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IDeviceDataService deviceDataService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }
    @PostMapping("/add")
    @ApiModelProperty(value = "添加绑定家属信息")
    public AjaxResult add(@RequestBody ElderDto elderDto){
        return toAjax(familyMemberService.add(elderDto));
    }

    @GetMapping("/my")
    @ApiModelProperty(value = "查询当前登录用户的老人及家属信息")
    public R<List<FamilyMemberElderVo>> listFamilyMembers(){
        return R.ok(familyMemberService.listFamilyMembers());
    }
    
    /**
     * 分页查询老人及家属信息列表
     */
    @GetMapping("/list-by-page")
    @ApiModelProperty(value = "分页查询老人及家属信息列表")
    public R<List<ElderMemberVo>> listByPage()
    {
        startPage();
        List<ElderMemberVo> list = familyMemberService.selectElderMemberVoList();
        return R.ok(list);
    }

    /**
     * 查询健康数据
     * @param device
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiModelProperty(value = "查询设备属性状态")
    public R<DevicePropertyResponseVo> queryDevicePropertyStatus(@RequestBody Device  device){
        ListVo listVo = deviceDataService.queryDevicePropertyStatus(device);
        // 构建新的嵌套结构
        DevicePropertyResponseVo responseVo = new DevicePropertyResponseVo();
        DevicePropertyResponseVo.ListDataVo listDataVo = new DevicePropertyResponseVo.ListDataVo();
        listDataVo.setPropertyStatusInfo(listVo.getPropertyStatusInfo());
        responseVo.setList(listDataVo);
        return R.ok(responseVo);
    }
    @GetMapping("/queryDeviceDataListByDay")
    @ApiModelProperty(value = "查一天设备数据列表")
    public R<List<HourlyDataVO>> queryDeviceDataListByDay(DeviceDataQueryDTO DeviceDataQuerydto){
        return R.ok(deviceDataService.queryDeviceDataListByDay(DeviceDataQuerydto));
    }
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiModelProperty(value = "查一天设备数据列表")
    public R<List<HourlyDataVO>> queryDeviceDataListByWeek(DeviceDataQueryDTO DeviceDataQuerydto){
        return R.ok(deviceDataService.queryDeviceDataListByWeek(DeviceDataQuerydto));
    }
}
